<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?php echo ($meta_title); ?>|管理平台</title>
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/module.css">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/style.css" media="all">
	<link rel="stylesheet" type="text/css" href="/Public/Admin/css/<?php echo (C("COLOR_STYLE")); ?>.css" media="all">
     <!--[if lt IE 9]>
    <script type="text/javascript" src="/Public/static/jquery-1.10.2.min.js"></script>
    <![endif]--><!--[if gte IE 9]><!-->
    <script type="text/javascript" src="/Public/static/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/jquery.mousewheel.js"></script>
     <!--<link rel="stylesheet" href="/Public/Admin/css/ace.min.css" id="main-ace-style" />-->
     <!--<link rel="stylesheet" href="/Public/Admin/css/bootstrap.min.css" />-->
    <!--<![endif]-->
    
</head>
<body>
    <!-- 头部 -->
    <div class="header">
        <!-- 主导航 -->
        <ul class="main-nav">
            <li style="width: 200px; color:#fff; font-size: 18px; font-weight: bold; text-align: center; ">
            懒人智库后台
            </li>
            <?php if(is_array($__MENU__["main"])): $i = 0; $__LIST__ = $__MENU__["main"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li class="<?php echo ((isset($menu["class"]) && ($menu["class"] !== ""))?($menu["class"]):''); ?>"><a href="<?php echo (U($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
        </ul>
        <!-- /主导航 -->

        <!-- 用户栏 -->
        <div class="user-bar">
            <a href="javascript:;" class="user-entrance"><i class="icon-user"></i></a>
            <ul class="nav-list user-menu hidden">
                <li class="manager">你好，<em title="<?php echo session('user_auth.username');?>"><?php echo session('user_auth.username');?></em></li>
                <li><a href="<?php echo U('User/updatePassword');?>">修改密码</a></li>
                <li><a href="<?php echo U('User/updateNickname');?>">修改昵称</a></li>
                <li><a href="<?php echo U('Public/logout');?>">退出</a></li>
            </ul>
        </div>
    </div>
    <!-- /头部 -->

    <!-- 边栏 -->
    <div class="sidebar">
        <!-- 子导航 -->
        
            <div id="subnav" class="subnav">
                <?php if(!empty($_extra_menu)): ?>
                    <?php echo extra_menu($_extra_menu,$__MENU__); endif; ?>
                <?php if(is_array($__MENU__["child"])): $i = 0; $__LIST__ = $__MENU__["child"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$sub_menu): $mod = ($i % 2 );++$i;?><!-- 子导航 -->
                    <?php if(!empty($sub_menu)): if(!empty($key)): ?><h3><i class="icon icon-unfold"></i><?php echo ($key); ?></h3><?php endif; ?>
                        <ul class="side-sub-menu">
                            <?php if(is_array($sub_menu)): $i = 0; $__LIST__ = $sub_menu;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li>
                                    <a class="item" href="<?php echo (U($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a>
                                </li><?php endforeach; endif; else: echo "" ;endif; ?>
                        </ul><?php endif; ?>
                    <!-- /子导航 --><?php endforeach; endif; else: echo "" ;endif; ?>
            </div>
        
        <!-- /子导航 -->
    </div>
    <!-- /边栏 -->

    <!-- 内容区 -->
    <div id="main-content">
        <div id="top-alert" class="fixed alert alert-error" style="display: none;">
            <button class="close fixed" style="margin-top: 4px;">&times;</button>
            <div class="alert-content">这是内容</div>
        </div>
        <div id="main" class="main">
            
            <!-- nav -->
            <?php if(!empty($_show_nav)): ?><div class="breadcrumb">
                <span>您的位置:</span>
                <?php $i = '1'; ?>
                <?php if(is_array($_nav)): foreach($_nav as $k=>$v): if($i == count($_nav)): ?><span><?php echo ($v); ?></span>
                    <?php else: ?>
                    <span><a href="<?php echo ($k); ?>"><?php echo ($v); ?></a>&gt;</span><?php endif; ?>
                    <?php $i = $i+1; endforeach; endif; ?>
            </div><?php endif; ?>
            <!-- nav -->
            

            
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/index.css">
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/upload.css">
    <script type="text/javascript" src="/Public/static/uploadify/jquery.uploadify.min.js"></script>
    <style>
        .data-table table { width: 100%; border-collapse: collapse;}
        .spec-li{float: left; border: 1px solid #cdcdcd; min-width: 35px; height: 30px; line-height: 30px; margin-left: 5px; text-align: center; border-radius: 2px; }
        .spec-select{ border:1px solid red; color:red;}
        .img-plus{
            position: relative;
        }

        .img-remove{
            position: absolute;
            right: 0;
            width: 20px;
            height: 20px;
            background:url(/Public/Admin/images/remove.png);
            background-size: 100% 100%;

        }
        .setheadimg{
            text-align: center;
            background-color: rgb(149, 133, 191);
            margin-top: 10px;
            border-radius: 5px;
            height: 20px;
            color: #fff;
        }
        li{
            float: left;
            margin-right: 10px; 
        }
        .upload-img-box .upload-pre-item{
            padding: 1px;
            width: 120px;
            height: 150px;
            overflow: hidden;
            text-align: center;
            cursor: pointer;
            border: 1px solid #ccc;
            transition: all .3s linear;
        }
        .up-img{
            height: 100px;
            width:100%
        }
    </style>
    <script type="text/javascript" src="/Public/static/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>发布/编辑商品</h2>
    </div>
    <form action="" method="post" class="form-horizontal" onkeydown="if (event.keyCode == 13) {
                return false;
            }">
        <input type="hidden" name="id" id="id" value="<?php echo ($data['goods_id']); ?>">

        <div class="form-item">
            <label class="item-label">商品分类<span class="check-tips"></span></label>
            <div class="controls">
                <select name="cate_id">
                    <?php if(!empty($clist)): if(is_array($clist)): $i = 0; $__LIST__ = $clist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($vo["cate_id"]); ?>" <?php if($data['cate_id']==$vo['cate_id']){ echo 'selected';} ?>><?php echo ($vo["title_show"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
                </select> 
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">所属中心<span class="check-tips"></span></label>
            <div class="controls">
                <select name="center_id">
                    <option value="0" >-请选择所属中心-</option>
                    <?php if(!empty($center)): if(is_array($center)): $i = 0; $__LIST__ = $center;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($vo["center_id"]); ?>" <?php if($data['center_id']==$vo['center_id']){ echo 'selected';} ?>><?php echo ($vo["center_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; endif; ?>
                </select> 
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">商品标题<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="goods_name" value="<?php echo ($data['goods_name']); ?>" placeholder="">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">商品主图</label><span class="check-tips"></span>
            <div class="controls">

                <div class="img-box full" style="width: 100%;">
                    <section class=" img-section">
                        <!--<p class="up-p">作品图片：<span class="up-span">最多可以上传5张图片，马上上传</span></p>-->
                        <div class="z_photo upimg-div clear" >
                            <?php if(!empty($data)):?>
                            <?php if(is_array($data["image_list"])): $i = 0; $__LIST__ = $data["image_list"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><section class="up-section fl">
                                    <span class="up-span"></span>
                                    <img src="/Public/Admin/images/a7.png" class="close-upimg">
                                    <img src="<?php echo ($vo); ?>" class="up-img">
                                    <p class="img-namep"></p>
                                    <input id="taglocation" name="taglocation" value="" type="hidden">
                                    <input id="tags" name="tags" value="" type="hidden">
                                    <input type='hidden' name='image_list[]' value="<?php echo ($vo); ?>" class='img-item img-url js-pic_urlfile' >
                                    <div class="setheadimg" onclick="setHeadImg(this);">设置为主图</div>
                                </section><?php endforeach; endif; else: echo "" ;endif; ?>
                            <?php endif;?>
                            <section class="z_file fl" style="<?php if($data['img_count']>=5){echo "display: none;";}?>">

                                     <img src="/Public/Admin/images/a11.png" class="add-img">

                                                                                  <input type="file" name="file" id="image_list" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple />
                                                                              </section>
                            </div>
                        </section>
                    </div>
                    <aside class="mask works-mask">
                        <div class="mask-content">
                            <p class="del-p">您确定要删除图片吗？</p>
                            <p class="check-p"><span class="del-com wsdel-ok">确定</span><span class="wsdel-no">取消</span></p>
                        </div>
                    </aside>
                </div>
            </div>
            <div class="form-item">
                <label class="item-label">主图</label>
                <div class="controls">
                    <input type="hidden" name="head_img" id="head-img" class="cover_id_face" value="<?php echo ($data['head_img']); ?>"/>
                    <img class="head-img-play" width="400px" src="<?php echo ($data['head_img']); ?>"/>
                </div>
            </div>

            <div class="form-item">
                <label class="item-label">单价</label>
                <div class="controls">
                    <input type="text" class="text input-large" name="price" value="<?php echo ($data['price']); ?>" id="price">
                </div>
            </div>
            <div class="form-item">
                <label class="item-label">收藏数</label>
                <div class="controls">
                    <input type="text" class="text input-large" name="collect_num" value="<?php echo ($data['collect_num']); ?>" id="price">
                </div>
            </div>

            <div class="form-item">
                <label class="item-label">自我介绍</label>
                <div class="controls">
                    <textarea rows="5" cols="20" id="content" class="text input-large kind-editor"  name="explain" ><?php echo ($data['explain']); ?></textarea>
                </div>
            </div>

            <div class="form-item">
                <label class="item-label">二维码</label><span class="check-tips"></span>
                <div class="controls">

                    <div class="img-box full" style="width: 100%;">
                        <section class=" img-section">
                            <!--<p class="up-p">作品图片：<span class="up-span">最多可以上传5张图片，马上上传</span></p>-->
                            <div class="z_photo upimg-div clear" >
                                <?php if(!empty($data)):?>
                                <?php if(is_array($data["qcode"])): $i = 0; $__LIST__ = $data["qcode"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><section class="up-section fl">
                                        <span class="up-span"></span>
                                        <img src="/Public/Admin/images/a7.png" class="close-upimg">
                                        <img src="<?php echo ($vo); ?>" class="up-img">
                                        <p class="img-namep"></p>
                                        <input id="taglocation" name="taglocation" value="" type="hidden">
                                        <input id="tags" name="tags" value="" type="hidden">
                                        <input type='hidden' name='qcode[]' value="<?php echo ($vo); ?>" class='img-item img-url js-pic_urlfile' >
                                    </section><?php endforeach; endif; else: echo "" ;endif; ?>
                                <?php endif;?>
                                <section class="z_file fl" style="<?php if($data['img_count']>=5){echo "display: none;";}?>">

                                         <img src="/Public/Admin/images/a11.png" class="add-img">

                                                                                      <input type="file" name="file" id="qcode" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple />
                                                                                  </section>
                                </div>
                            </section>
                        </div>
                        <aside class="mask works-mask">
                            <div class="mask-content">
                                <p class="del-p">您确定要删除图片吗？</p>
                                <p class="check-p"><span class="del-com wsdel-ok">确定</span><span class="wsdel-no">取消</span></p>
                            </div>
                        </aside>
                    </div>
                </div>

                <div class="form-item">
                    <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1); return false;">返 回</button>
                </div>
            </form>
        
        </div>
        <div class="cont-ft">
            <div class="copyright">
                <div class="fl">感谢使用 管理平台</div>
            </div>
        </div>
    </div>
    <!-- /内容区 -->
    <script type="text/javascript">
    (function(){
        var ThinkPHP = window.Think = {
            "ROOT"   : "", //当前网站地址
            "APP"    : "/admin.php?s=", //当前项目地址
            "PUBLIC" : "/Public", //项目公共目录地址
            "DEEP"   : "<?php echo C('URL_PATHINFO_DEPR');?>", //PATHINFO分割符
            "MODEL"  : ["<?php echo C('URL_MODEL');?>", "<?php echo C('URL_CASE_INSENSITIVE');?>", "<?php echo C('URL_HTML_SUFFIX');?>"],
            "VAR"    : ["<?php echo C('VAR_MODULE');?>", "<?php echo C('VAR_CONTROLLER');?>", "<?php echo C('VAR_ACTION');?>"]
        }
    })();
    </script>
    <script type="text/javascript" src="/Public/static/think.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/common.js"></script>
    <script type="text/javascript">
        +function(){
            var $window = $(window), $subnav = $("#subnav"), url;
            $window.resize(function(){
                $("#main").css("min-height", $window.height() - 130);
            }).resize();

            /* 左边菜单高亮 */
            url = window.location.pathname + window.location.search;
            url = url.replace(/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)|(\/(group)\/\d+)|(&group=\d+)/, "");
            $subnav.find("a[href='" + url + "']").parent().addClass("current");

            /* 左边菜单显示收起 */
            $("#subnav").on("click", "h3", function(){
                var $this = $(this);
                $this.find(".icon").toggleClass("icon-fold");
                $this.next().slideToggle("fast").siblings(".side-sub-menu:visible").
                      prev("h3").find("i").addClass("icon-fold").end().end().hide();
            });

            $("#subnav h3 a").click(function(e){e.stopPropagation()});

            /* 头部管理员菜单 */
            $(".user-bar").mouseenter(function(){
                var userMenu = $(this).children(".user-menu ");
                userMenu.removeClass("hidden");
                clearTimeout(userMenu.data("timeout"));
            }).mouseleave(function(){
                var userMenu = $(this).children(".user-menu");
                userMenu.data("timeout") && clearTimeout(userMenu.data("timeout"));
                userMenu.data("timeout", setTimeout(function(){userMenu.addClass("hidden")}, 100));
            });

	        /* 表单获取焦点变色 */
	        $("form").on("focus", "input", function(){
		        $(this).addClass('focus');
	        }).on("blur","input",function(){
				        $(this).removeClass('focus');
			        });
		    $("form").on("focus", "textarea", function(){
			    $(this).closest('label').addClass('focus');
		    }).on("blur","textarea",function(){
			    $(this).closest('label').removeClass('focus');
		    });

            // 导航栏超出窗口高度后的模拟滚动条
            var sHeight = $(".sidebar").height();
            var subHeight  = $(".subnav").height();
            var diff = subHeight - sHeight; //250
            var sub = $(".subnav");
            if(diff > 0){
                $(window).mousewheel(function(event, delta){
                    if(delta>0){
                        if(parseInt(sub.css('marginTop'))>-10){
                            sub.css('marginTop','0px');
                        }else{
                            sub.css('marginTop','+='+10);
                        }
                    }else{
                        if(parseInt(sub.css('marginTop'))<'-'+(diff-10)){
                            sub.css('marginTop','-'+(diff-10));
                        }else{
                            sub.css('marginTop','-='+10);
                        }
                    }
                });
            }
        }();
    </script>
    
            <script charset="utf-8" src="/Public/static/kindeditor/kindeditor-min.js"></script>
            <script charset="utf-8" src="/Public/static/kindeditor/zh_CN.js"></script>
            <script src="/Public/static/thinkbox/jquery.thinkbox.js"></script>
            <script type="text/javascript">
                        KindEditor.ready(function (K) {
                            window.editor = K.create('textarea[class="kind-editor"]', {
                                //allowFileManager : false
                                minWidth: 900,
                                minHeight: 300,
                                afterBlur: function () {
                                    this.sync();
                                },
                            });
                        });
                        //导航高亮
                        highlight_subnav('<?php echo U('Goods / index');?>');
            </script>
            <script type="text/javascript">
                $(function () {
                    var maxupload = 5;
                    var delParent;
                    var defaults = {
                        fileType: ["jpg", "png", "bmp", "jpeg"], // 上传文件的类型
                        fileSize: 1024 * 1024 * 1                  // 上传文件的大小 10M
                    };
                    /*点击图片的文本框*/
                    $(".file").change(function () {
                        var idFile = $(this).attr("id");
                        var file = document.getElementById(idFile);
                        var imgContainer = $(this).parents(".z_photo"); //存放图片的父亲元素
                        var fileList = file.files; //获取的图片文件

                        var input = $(this).parent(); //文本框的父亲元素
                        var imgArr = [];
                        //遍历得到的图片文件
                        var numUp = imgContainer.find(".up-section").length;
                        var totalNum = numUp + fileList.length; //总的数量
                        if (fileList.length > maxupload || totalNum > maxupload) {
                            alert("上传图片数目不可以超过" + maxupload + "个，请重新选择"); //一次选择上传超过5个 或者是已经上传和这次上传的到的总数也不可以超过5个
                        } else if (numUp < maxupload) {

                            fileList = validateUp(fileList);
                            for (var i = 0; i < fileList.length; i++) {
                                var filedata = fileList[i];
                                console.log(filedata);
                                var imgUrl = window.URL.createObjectURL(fileList[i]);
                                imgArr.push(imgUrl);
                                var $section = $("<section class='up-section fl loading'>");
                                imgContainer.prepend($section);
                                var $span = $("<span class='up-span'>");
                                $span.appendTo($section);
                                var $img0 = $("<img class='close-upimg'>").on("click", function (event) {
                                    event.preventDefault();
                                    event.stopPropagation();
                                    $(".works-mask").show();
                                    delParent = $(this).parent();
                                });
                                $img0.attr("src", "/Public/Admin/images/a7.png").appendTo($section);
                                var $img = $("<img class='up-img up-opcity'>");
                                $img.attr("src", imgArr[i]);
                                $img.appendTo($section);
                                var formData = new FormData();
                                formData.append("download", filedata);
                                $.ajax({
                                    url: "<?php echo U('File/uploadImage');?>",
                                    type: "POST",
                                    data: formData,
                                    /**
                                     *必须false才会自动加上正确的Content-Type
                                     */
                                    contentType: false,
                                    /**
                                     * 必须false才会避开jQuery对 formdata 的默认处理
                                     * XMLHttpRequest会对 formdata 进行正确的处理
                                     */
                                    processData: false,
                                    success: function (data) {
                                        var $imginput = $("<input type='hidden' class='img-item' name='" + idFile + "[]'>");
                                        $imginput.val(data.path);
                                        $imginput.appendTo($section);
                                        if (idFile != 'qcode') {
                                            var $div = $("<div class='setheadimg' onClick='setHeadImg(this);'>");
                                            $div.html('设置为主图');
                                        }

                                        $div.appendTo($section);
                                    },
                                    error: function () {
                                        alert("上传失败！");
                                        //                                $("#imgWait").hide();
                                    }
                                });
                                var $p = $("<p class='img-name-p'>");
                                $p.html(fileList[i].name).appendTo($section);
                                var $input = $("<input id='taglocation' name='taglocation' value='' type='hidden'>");
                                $input.appendTo($section);
                                var $input2 = $("<input id='tags' name='tags' value='' type='hidden'/>");
                                $input2.appendTo($section);
                            }
                        }
                        setTimeout(function () {
                            $(".up-section").removeClass("loading");
                            $(".up-img").removeClass("up-opcity");
                        }, 450);
                        numUp = imgContainer.find(".up-section").length;
                        if (numUp >= maxupload) {
                            $(this).parent().hide();
                        }

                        //input内容清空
                        $(this).val("");
                    });
                    $(".z_photo").delegate(".close-upimg", "click", function () {
                        $(".works-mask").show();
                        delParent = $(this).parent();
                    });
                    $(".wsdel-ok").click(function () {
                        $(".works-mask").hide();
                        var numUp = delParent.siblings().length;
                        if (numUp < maxupload + 1) {
                            delParent.parent().find(".z_file").show();
                        }
                        delParent.remove();
                    });
                    $(".wsdel-no").click(function () {
                        $(".works-mask").hide();
                    });
                    function validateUp(files) {
                        var arrFiles = []; //替换的文件数组
                        for (var i = 0, file; file = files[i]; i++) {
                            //获取文件上传的后缀名
                            var newStr = file.name.split("").reverse().join("");
                            if (newStr.split(".")[0] != null) {
                                var type = newStr.split(".")[0].split("").reverse().join("");
                                console.log(type + "===type===");
                                if (jQuery.inArray(type, defaults.fileType) > -1) {
                                    // 类型符合，可以上传
                                    if (file.size >= defaults.fileSize) {
                                        alert(file.size);
                                        alert('您这个"' + file.name + '"文件大小过大');
                                    } else {
                                        // 在这里需要判断当前所有文件中
                                        arrFiles.push(file);
                                    }
                                } else {
                                    alert('您这个"' + file.name + '"上传类型不符合');
                                }
                            } else {
                                alert('您这个"' + file.name + '"没有类型, 无法识别');
                            }
                        }
                        return arrFiles;
                    }

                });
            </script>
            <script type="text/javascript">

                $(document).ready(function () {
                    $('.js-li').on("click", function () {
                        var obj = $(this);
                        var is_select = obj.attr('is_select');
                        if (is_select == '1') {
                            obj.removeClass('spec-select');
                            obj.attr('is_select', '0');
                        } else {
                            obj.addClass('spec-select');
                            obj.attr('is_select', '1');
                        }
                    });
                    //                    $('.js-create-but').on("click", function () {
                    //                        var select_data = new Array();
                    //                        obj.find('.js-li').each(function () {
                    //                            var sonobj = $(this);
                    //                            if (sonobj.attr('is_select') == '1') {
                    //                                
                    //                            }
                    //
                    //                        });
                    //                        $('.js-create-div').html('<input name="spec[]" />')
                    //                    });

                    $('.js-create-but').on("click", function () {
                        var discount_price = $('#discount_price').val();
                        if (discount_price == '') {
                            alert('请先填写单价');
                            return false;
                        }

                        var select_data = new Array();
                        $('.js-spec-tr').each(function () {
                            var obj = $(this);
                            var spec_id = obj.attr('spec_id');
                            var son_data = [];
                            var i = 0;
                            obj.find('.js-li').each(function () {
                                var sonobj = $(this);
                                if (sonobj.attr('is_select') == '1') {
                                    son_data[i] = parseInt(sonobj.attr('spec_son_id'));
                                    i++;
                                }
                            });
                            select_data[spec_id] = son_data;
                        });
                        var goods_id = $('#id').val();
                        if (goods_id) {
                            $.post("<?php echo U('Goods/specSonCombination');?>", {data: select_data, discount_price: discount_price, goods_id: goods_id}, function (res) {
                                $('.js-create-list').append(res);
                            });
                        } else {
                            $.post("<?php echo U('Goods/specSonCombination');?>", {data: select_data, discount_price: discount_price}, function (res) {
                                $('.js-create-list').html(res);
                            });
                        }



                    });
                });
                // 执行组合排列的函数
                function doExchange(arr) {
                    var len = arr.length;
                    // 当数组大于等于2个的时候
                    if (len >= 2) {
                        // 第一个数组的长度
                        var len1 = arr[0].length;
                        // 第二个数组的长度
                        var len2 = arr[1].length;
                        // 2个数组产生的组合数
                        var lenBoth = len1 * len2;
                        //  申明一个新数组,做数据暂存
                        var items = new Array(lenBoth);
                        // 申明新数组的索引
                        var index = 0;
                        // 2层嵌套循环,将组合放到新数组中
                        for (var i = 0; i < len1; i++) {
                            for (var j = 0; j < len2; j++) {
                                items[index] = arr[0][i] + "|" + arr[1][j];
                                index++;
                            }
                        }
                        // 将新组合的数组并到原数组中
                        var newArr = new Array(len - 1);
                        for (var i = 2; i < arr.length; i++) {
                            newArr[i - 1] = arr[i];
                        }
                        newArr[0] = items;
                        // 执行回调
                        return doExchange(newArr);
                    } else {
                        return arr[0];
                    }
                }
            </script>

            <script type="text/javascript">

                function setHeadImg(item) {
                    var head_img = $(item).prev(".img-item").val();
                    console.log(head_img);
                    $('#head-img').val(head_img);
                    $('#head-img').next('img').attr('src', '' + head_img);
                }

                function removeitem(id) {
                    if (window.confirm('删除该规格可能会导致历史订单出错,你确定删除吗？')) {
                        $.post("<?php echo U('Goods/removeGoodsSon');?>", {id: id}, function (res) {
                            if (res.status) {
                                var item = '#gs-item-' + id;
                                $(item).remove();
                            } else {
                                alert('删除失败!')
                            }
                        });
                    }
                }
            </script>
        
</body>
</html>